package logic

import (
	"context"
	"everyone/B/rpc_B/everyone"
	"everyone/B/rpc_B/internal/svc"
	"everyone/B/rpc_B/model/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsCreateLogic {
	return &GoodsCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsCreateLogic) GoodsCreate(in *everyone.GoodsCreateRequest) (*everyone.GoodsCreateResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{
		GoodsTitle:  in.GoodsTitle,
		GoodsNum:    in.GoodsNum,
		GoodsImage:  in.GoodsImage,
		GoodsPrice:  float64(in.GoodsPrice),
		GoodsLike:   in.GoodsLike,
		GoodsStatue: in.GoodsStatue,
	}
	err := g.Create()
	if err != nil {
		logx.Error("商品添加及失败")
	}
	return &everyone.GoodsCreateResponse{
		GoodsId: int64(g.ID),
	}, nil
}
